import axios from './request'

export default {
  /**
   * get 请求方式
   */
  fetch(url, params = {}) {
    // 请求路径为 http://www.baidu.com?id=XXX
    return new Promise((resolve, reject) => {
      axios.get(url, {
        params: params
      })
        .then(response => {
          resolve(response.data)
        })
        .catch(err => {
          reject(err)
        })
    })
  },
  /**
   * post 请求方式
   */
  post(url, data = {}) {
    return new Promise((resolve, reject) => {
      axios.post(url, data)
        .then(response => {
          resolve(response.data)
        })
        .catch(err => {
          reject(err)
        })
    })
  },
  /**
   * put 请求方式
   */
  put(url, data = {}) {
    return new Promise((resolve, reject) => {
      axios.put(url, data)
        .then(response => {
          resolve(response.data)
        })
        .catch(err => {
          reject(err)
        })
    })
  },
  /**
   * delete 请求方式
   */
  deleteFun(url, data = {}) {
    return new Promise((resolve, reject) => {
      axios.delete(url, {
        params: data
      })
        .then(response => {
          resolve(response.data)
        })
        .catch(err => {
          reject(err)
        })
    })
  }
}
